<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>持明法洲登录页面</title>
		<link rel="stylesheet" href="layui/css/layui.css">
		 <link rel="stylesheet" href="css/main.css"  media="all">
		 <link rel="stylesheet" href="css/plugins/font-awesome-4.7.0/css/font-awesome.min.css"  media="all">
	</head>
	
	<body class="layui-layout-login">
	<div class="login-bg">
	    <div class="cover"></div>
	</div>
	<div class="login-content" >
	    <h1 class="login-box-title"><i class="fa fa-fw fa-user"></i>登录</h1>
	    <form class="layui-form" id="loginForm" method="post">
			
	        <div class="layui-form-item">
	            <label class="layui-icon layui-icon-username" for="username"></label>
	            <input class="layui-input" type="text" name="username" id="username" lay-verify="required" placeholder="用户名">
	        </div>
			
	        <div class="layui-form-item">
	            <label class="layui-icon layui-icon-password" for="password"></label>
	            <input class="layui-input" type="password" name="password" id="password" lay-verify="required" placeholder="密码">
	        </div>
			
	        <div class="layui-form-item captcha-item">
	            <label class="layui-icon layui-icon-vercode"></label>
	            <input class="layui-input" type="text" name="validateCode" lay-verify="required" autocomplete="off" placeholder="验证码">
				<img class="captcha-img" onclick="this.src='${pageContext.request.contextPath}/validateCode/getCode?id='+Math.random()" src="${pageContext.request.contextPath}/validateCode/getCode"/>
	        </div>
			
	        <button class="layui-btn layui-btn-fluid ajax-login"  lay-submit lay-filter="login-submit"><i class="fa fa-sign-in fa-lg fa-fw"></i> 登录</button>
	    </form>
	</div>
	</body>
	<script src="layui/layui.js" type="text/javascript"></script>
	<script>
		layui.use(['form', 'jquery'], function () {
			var $ = layui.jquery;
			var form = layui.form;

			//登录提交
			form.on('submit(login-submit)', function (data) {
				console.log(data.elem); //被执行事件的元素DOM对象，一般为button对象
				console.log(data.form); //被执行提交的form对象，一般在存在form标签时才会返回
				console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
				$.ajax({
					url:'${pageContext.request.contextPath}/admin/login'
					,data:$("#loginForm").serialize()
					,success:function (result) {
						if(result.flag){
							$("#loginForm")[0].reset();
							window.location.href='${pageContext.request.contextPath}/main.jsp'
						}else if(result.flag='false'){
							layer.msg('账号或密码输入错误!!')
						} else{
							layer.msg('验证码错误!!!')
						}


					}
				})
				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		});
	</script>
</html>
